<?php


namespace app\model\partner;


use app\model\config\RegionModel;
use think\Model;
use think\model\concern\SoftDelete;

class PartnerCityModel extends Model
{
    protected $name = 'partner_city';
    protected $autoWriteTimestamp = true;

    use  SoftDelete;
    protected $defaultSoftDelete = 0;

//    function cityName()
//    {
//        return $this->hasOne(RegionModel::class, 'id', 'city_id')->bind(['city_name' => 'name']);
//    }

    public static function onBeforeWrite(Model $model)
    {
        $name = RegionModel::where('id', $model->city_id)->value('name');
        $model->appendData(['city_name' => $name]);
    }
}